package edu.cmu.cs.cs214.hw9.client.controllers;

import javax.swing.JFrame;

import edu.cmu.cs.cs214.hw9.client.controllers.eventhandlers.*;
import edu.cmu.cs.cs214.hw9.client.gui.*;
import edu.cmu.cs.cs214.hw9.datatypes.User;

/**
 * Extends the generic facelook controller by keeping track of user sessions and handling session-related events.
 * One session controller should be spawned for every user that logs into Facelook.
 */
public class SessionController extends FacelookController {
	private User currentUser;
	
	/**
	 * Constructs a new session-aware controller for a currently logged in user.
	 * 
	 * @param model The model/database to use.
	 * @param frame The JFrame associated with the current screen. (For switching screens, etc.) 
	 * @param view A handle to the user's current screen.
	 * @param currentUser The currently logged in user.
	 */
	public SessionController(BackendCacheAdapter model, JFrame frame, FacelookScreen view, User currentUser) {
		super(model, frame, view);
		this.currentUser = currentUser;
		
		// Overwrite existing event map with the events we want to handle.
		eventMap.clear();
		eventMap.put(Event.GO_TO_FEED, new GotoFeedHandler(this));
		eventMap.put(Event.GO_TO_FRIENDS, new GotoFriendsHandler(this));
		eventMap.put(Event.GO_TO_PROFILE, new GotoProfileHandler(this));
		eventMap.put(Event.ADD_FRIEND, new AddFriendHandler(this));
		eventMap.put(Event.REMOVE_FRIEND, new RemoveFriendHandler(this));
		eventMap.put(Event.SEARCH_FRIENDS, new SearchHandler(this));
		eventMap.put(Event.POST_STATUS, new PostStatusHandler(this));
	}
	
	/**
	 * Gets the user currently associated with this controller
	 * 
	 * @return Associated user.
	 */
	public User getCurrentUser() { return currentUser; }
}
